package org.lc.service.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lc.platform.base.result.Result;
import org.lc.platform.mybatis.crud.controller.CrudBaseController;
import org.lc.service.system.dto.RolePermissionDto;
import org.lc.service.system.dto.SysPermissionDto;
import org.lc.service.system.entity.SysPermission;
import org.lc.service.system.service.SysPermissionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permission")
@Validated
@Tag(name = "权限点模块")
public class SysPermissionController extends CrudBaseController<SysPermission, SysPermission, SysPermissionDto, SysPermissionService> {
    public SysPermissionController(SysPermissionService service) {
        super(service);
    }


    @Operation(summary = "权限点是否存在")
    @GetMapping("/exits/{permission}/{menuId}")
    private Result<Boolean> getPermissionExits(@PathVariable("permission") String permission, @PathVariable("menuId") String menuId) {
        return Result.data(this.getService().getPermissionExits(permission, menuId));
    }

    @Operation(summary = "批量添加角色权限点")
    @PostMapping("/batch/role")
    private Result<Boolean> batchRolePermission(@RequestBody RolePermissionDto data) {
        return Result.data(this.getService().batchRolePermission(data.getRole(),data.getPermissions()));
    }
}
